#include <iostream>
#include <memory>
#include <vector>
#include <limits>
#include <algorithm>
#include <unistd.h>
#include <chrono>

using namespace std;

int vector_test(){
    vector<int> vec;
    vec.reserve(1024);
    vec.assign({1,2,3,4,5});

    vector<int> new_vec{6,7,8,9,10};
    vec = new_vec;  //use move to assign
    cout<<"size: "<<vec.size()<<endl;
    cout<<"capacity: "<<vec.capacity()<<endl;
    vec.shrink_to_fit();
    cout<<"capacity: "<<vec.capacity()<<endl;
    cout<<"max_size: "<<vec.max_size()<<endl;

    //get item
    cout<<vec.front()<<" "<<vec[1]<<" "<<vec.at(2)<<" "<<vec.at(3)<<" "<<vec.back()<<endl;

    for (auto i=vec.rbegin(); i!=vec.rend(); i++)
        cout<<*i<<" ";
    cout<<endl;

    vec.push_back(999);

    for (auto i=vec.begin(); i!=vec.end(); i++)
        cout<<*i<<" ";
    cout<<endl;

    vec.pop_back();
    vec.insert(vec.end(), new_vec.begin(), new_vec.end());

    for (auto i=vec.begin(); i!=vec.end(); i++)
        cout<<*i<<" ";
    cout<<endl;

    vec.resize(12,99999);
    for (auto i=vec.begin(); i!=vec.end(); i++)
        cout<<*i<<" ";
    cout<<endl;

    //emplace() 在插入元素时，是在容器的指定位置直接构造元素，而不是先单独生成，再将其复制（或移动）到容器中。因此，在实际使用中，推荐大家优先使用 emplace()。
    vec.emplace_back(10);
    for (auto i=vec.begin(); i!=vec.end(); i++)
        cout<<*i<<" ";
    cout<<endl;
}
